<cfsetting requesttimeout="6000">

<cfif IsUserInRole("Super User") or IsUserInRole("Regional Admin")>

	<cfparam name="resetFilters" default="false">
	<cfset isFiltered = false />
	<cfset queryParams = StructNew() />
	<cfset firstProgramYear = "2011-2012" />

	<cfif NOT IsDefined("client.evaluations.programYears") or resetFilters>
		<cfset client.evaluations.programYears = request.currentProgramYear>
	<cfelseif IsDefined("filterProgramYear")>
		<cfset client.evaluations.programYears = filterProgramYear>
	</cfif>
	<cfif client.evaluations.programYears neq request.currentProgramYear>
		<cfset isFiltered = true />
		<cfset queryParams.programYears = client.evaluations.programYears />
	<cfelse>
		<cfset queryParams.programYears = request.currentProgramYear />
	</cfif>
	
	<!--- <cfset client.evaluations.programYears = request.currentProgramYear />
	<cfset queryParams.programYears = client.evaluations.programYears />--->
	
	<!--- <cfif NOT IsDefined("client.evaluations.workshopIDs") or resetFilters>
		<cfset client.evaluations.workshopIDs = "All">
	<cfelseif IsDefined("filterWorkshopIDs")>
		<cfset client.evaluations.workshopIDs = filterWorkshopIDs>
	</cfif>
	<cfif client.evaluations.workshopIDs neq "All">
		<cfset isFiltered = true />
		<cfset queryParams.workshopIDs = client.evaluations.workshopIDs />
	</cfif> --->
	
	<cfif NOT IsDefined("client.evaluations.organizationIDs") or resetFilters>
		<cfset client.evaluations.organizationIDs = "All">
	<cfelseif IsDefined("filterOrganizationIDs")>
		<cfset client.evaluations.organizationIDs = filterOrganizationIDs>
	</cfif>
	<cfif client.evaluations.organizationIDs neq "All">
		<cfset isFiltered = true />
		<cfset queryParams.organizationIDs = client.evaluations.organizationIDs />
		<cfset filterRegionIDs = "All" />
	</cfif>
	
	<cfif IsUserInRole("Super User")>
		<cfif NOT IsDefined("client.evaluations.regionIDs") or resetFilters>
			<cfset client.evaluations.regionIDs = "All">
		<cfelseif IsDefined("filterRegionIDs")>
			<cfset client.evaluations.regionIDs = filterRegionIDs>
		</cfif>
	<cfelseif IsUserInRole("Regional Admin")>
		<cfset client.evaluations.regionIDs = request.authUser.regionID>
	</cfif>
	<cfif client.evaluations.regionIDs neq "All">
		<cfset isFiltered = true />
		<cfset queryParams.regionIDs = client.evaluations.regionIDs />
	</cfif>
	
	<cfwddx action="cfml2wddx" input="#queryParams#" output="client.evaluations.queryParamsWDDX" />
	
	<cfscript>
		organizationGateway = new assets.calgrants.com.gateway.OrganizationGateway();
		organizations = organizationGateway.query(regionIDs = IIf(IsUserInRole("Regional Admin"), request.authUser.regionID, ""), Organization_ID = IIf(IsUserInRole("Organizer") OR IsUserInRole("Site Contact"), request.authUser.organizationID, ""));
		storedProcedureGateway = new assets.calgrants.com.gateway.StoredProcedureGateway();
		regions = storedProcedureGateway.call("getDistinctRegions");
		evaluationGateway = new assets.calgrants.com.gateway.EvaluationGateway();
		evaluations = evaluationGateway.report(argumentCollection = queryParams);
		if (ArrayLen(evaluations) gt 0) {
			evaluationCount = evaluations[1].Response_Count + evaluations[1].No_Response_Count;
		} else {
			evaluationCount = 0;
		}
	</cfscript>

	<h3>Exit Surveys<cfif isFiltered> <small><em>filtered</em></small></cfif></h3>
	
	<cfoutput>
	 
		<div class="row-fluid" style="margin-bottom: 10px;">
			<div class="span12">
				<a id="filterLink" href="##" class="btn btn-success" onclick="toggleFilter('filter')">Show filters</a>
				<!--- <div class="btn-group">
					<button class="btn dropdown-toggle" data-toggle="dropdown">Actions</button>
					<button class="btn dropdown-toggle" data-toggle="dropdown"><span class="caret"></span></button>
					<ul class="dropdown-menu">
						<cfif ArrayLen(evaluations) gt 0>
							<li><a href="?action=export&collection=evaluations" target="_new">Export</a></li>
						</cfif>
					</ul>
				</div> --->
				<span class="pull-right"><strong>Count:</strong> #evaluationCount#</span>
			</div>
		</div>
		
		<cfform name="evaluationsForm" id="evaluationsForm" action="#script_name#" method="post">
			<cfinput type="hidden" name="view" value="#view#">
			<!--- Filters --->
			<div id="filter" class="alert alert-info alert-block" style="display: none;">
				<h4>Filters</h4>
				<table cellpadding="6">
					<tr valign="top">
						<td>
							<label>Program Year</label>
							<cfselect name="filterProgramYear" size="1" multiple="false" required="yes" message="Program Year filter is required" style="width: 150px;">
								<cfloop index="y" from="#ListFirst(firstProgramYear, '-')#" to="#ListFirst(application.currentProgramYear, '-')#">
									<cfset py = "#y#-" & y+1>
									<option value="#py#"<cfif client.evaluations.programYears eq py> selected</cfif>>#py#</option>
								</cfloop>
							</cfselect>
						</td>
						<cfif IsUserInRole("Super User")>
							<td>
								<label>Region</label>
								<cfselect name="filterRegionIDs" size="7" multiple="true" required="yes" message="Region filter is required" style="width: 150px;">
									<option value="All"<cfif client.evaluations.regionIDs eq "All"> selected</cfif>>All</option>
									<cfloop query="regions">
										<option value="#Region_ID#"<cfif ListFind(client.evaluations.regionIDs, Region_ID)> selected</cfif>>#Region_ID#</option>
									</cfloop>
								</cfselect>
							</td>
						</cfif>
						<td>
							<label>Organizations</label>
							<cfselect name="filterOrganizationIDs" size="7" multiple="true" required="yes" message="Organizations filter is required" style="width: auto;">
								<option value="All"<cfif client.evaluations.organizationIDs eq "All"> selected</cfif>>All</option>
								<cfloop query="organizations">
									<option value="#Organization_ID#"<cfif ListFind(client.evaluations.organizationIDs, Organization_ID)> selected</cfif>>#Organization# - #City#</option>
								</cfloop>
							</cfselect>
						</td>
						<!--- <td>
							<label>Follow Up</label>
							<cfif client.students.programYears neq "All" and client.students.programYears gte "2012-2013">
								<cfselect name="filterFollowUp" size="1" multiple="false" required="yes" message="Follow Up filter is required" style="width: 150px;">
									<option value="All"<cfif client.students.followUp eq "All"> selected</cfif>>All</option>
									<option value="Yes"<cfif client.students.followUp eq "Yes"> selected</cfif>>Yes</option>
									<option value="No"<cfif client.students.followUp eq "No"> selected</cfif>>No</option>
								</cfselect>
							<cfelse>
								<span class="muted"><small>Not available as filtered</small></span>
							</cfif>
						</td>
						<td>
							<label>Follow Up Status</label>
							<cfif client.students.programYears neq "All" and client.students.programYears gte "2012-2013">
								<cfselect name="filterFollowUpStatus" size="1" multiple="false" required="yes" message="Follow Up Status filter is required" style="width: 150px;">
									<option value="All"<cfif client.students.followUpStatus eq "All"> selected</cfif>>All</option>
									<option value="Complete"<cfif client.students.followUpStatus eq "Complete"> selected</cfif>>Complete</option>
									<option value="Not Complete"<cfif client.students.followUpStatus eq "Not Complete"> selected</cfif>>Not Complete</option>
								</cfselect>
							<cfelse>
								<span class="muted"><small>Not available as filtered</small></span>
							</cfif>
						</td> --->
					</tr>
					<tr>
						<td colspan="5">
							<button type="submit" class="btn btn-info">Apply</button> <a href="#script_name#?view=exitSurveys&resetFilters=true" class="btn btn-info">Clear</a>
						</td>
					</tr>
				</table>
			</div>
		</cfform>
	
	</cfoutput>
		
	<cfif evaluationCount gt 0>
	
		<!--- <cfdump var="#questions#" label="questions" expand="no">
		<cfdump var="#answers#" label="questions" expand="no">
		<cfdump var="#evaluations#" label="questions" expand="no">
		<cfabort> --->
	
		<script type="text/javascript">
			
			var parseQuestions = function(questions) {
				for (var q = 0; q < questions.length; q++) {
					questions[q].QUESTION_NUMBER = parseInt(questions[q].QUESTION_NUMBER);
					questions[q].RESPONSE_COUNT = parseInt(questions[q].RESPONSE_COUNT);
					questions[q].MULTI_RESPONSE_COUNT = parseInt(questions[q].MULTI_RESPONSE_COUNT);
					questions[q].NO_RESPONSE_COUNT = parseInt(questions[q].NO_RESPONSE_COUNT);
				}
				return questions;
			}
			
			var parseAnswers = function(answers) {
				for (var a = 0; a < answers.length; a++) {
					if (answers[a].ANSWER === true) {
						answers[a].ANSWER = "Yes ";
					} else if (answers[a].ANSWER === false) {
						answers[a].ANSWER = "No ";
					}
					answers[a].ANSWER_NUMBER = parseInt(answers[a].ANSWER_NUMBER);
					answers[a].RESPONSE_COUNT = parseInt(answers[a].RESPONSE_COUNT);
					answers[a].RESPONSE_PERCENT = parseFloat(answers[a].RESPONSE_PERCENT);
					//answers[a].RESPONSE_OTHER = answers[a].ANSWER_VALUES.toString();
					answers[a].EXPLODE = false;
				}
				return answers;
			}
	
			<cfoutput>
				var questions = #SerializeJSON(evaluations)#;
			</cfoutput>
			
			var pieLabelTemplate = "#= dataItem.ANSWER# - #= dataItem.RESPONSE_PERCENT#%";
			var pieLegendTemplate = "#= dataItem.ANSWER# - #= dataItem.RESPONSE_PERCENT#%";
			//var pieTooltipTemplate = "#= dataItem.ANSWER# - #= dataItem.RESPONSE_COUNT#";
			var pieTooltipTemplate = "#= dataItem.RESPONSE_COUNT# responses = #= dataItem.RESPONSE_PERCENT#%";
			var barLabelTemplate = "#= dataItem.ANSWER# - #= dataItem.RESPONSE_PERCENT#%";
			var barLegendTemplate = "#= text#";
			var barTooltipTemplate = "#= dataItem.RESPONSE_COUNT# responses = #= dataItem.RESPONSE_PERCENT#%";
			var labelFont = "12px Arial,Helvetical,sans-serif";
			var legendFont = "12px Arial,Helvetical,sans-serif";
			var tooltipFont = "12px Arial,Helvetical,sans-serif";
			
			renderPieChart = function(q) {
				var question = questions[q-1];
				var answers = parseAnswers(question.ANSWERS);
				$("#q" + q + "Chart").kendoChart({
					theme: $(document).data("kendoSkin") || "metro",
					dataSource: answers,
					series: [{
						type: "pie",
						field: "RESPONSE_PERCENT",
						categoryField: "ANSWER",
						explodeField: "EXPLODE",
						labels: {
							visible: true,
							align: "circle",
							font: labelFont,
							template: pieLabelTemplate,
							distance: 20
						},
						padding: 50
					}],
					legend: {
						visible: false,
						position: "left",
						labels: {
							font: legendFont,
							template: pieLegendTemplate
						}
					},
					tooltip: {
						visible: true,
						font: tooltipFont,
						template: pieTooltipTemplate
					}
				})
			}
			
			renderBarChart = function(q) {
				var question = questions[q-1];
				var answers = parseAnswers(question.ANSWERS);
				$("#q" + q + "Chart").kendoChart({
					theme: $(document).data("kendoSkin") || "metro",
					dataSource: answers,
					plotArea: {
						margin: {
							right: 200
						}
					},
					series: [{
						type: "bar",
						field: "RESPONSE_PERCENT",
						categoryField: "ANSWER",
						labels: {visible: true, font: labelFont, template: barLabelTemplate, position: "outsideEnd"},
						missingValue: "zero",
						gap: 0.4,
						spacing: 0.2,
						markers: {visible: true, border: {width: 2, size: 6}},
						padding: 50
					}],
					valueAxis: {
						title: {visible: false, text: "valueAxis"},
						labels: {template: "#= value#%"},
						majorGridLines: {visible: true, color: "gray"},
						majorTicks: {visible: true, color: "gray"},
						minorGridLines: {visible: false, color: "silver"},
						minorTicks: {visible: false, color: "silver"},
						plotBands: [{
							from: 49,
							to: 51,
							color: "gray",
							opacity: 0.3
						}]
					},
					categoryAxis: {
						title: {visible: false, text: "categoryAxis"},
						majorGridLines: {visible: false},
						majorTicks: {visible: false}
					},
					legend: {
						visible: false,
						position: "left",
						labels: {font: legendFont, template: barLegendTemplate}
					},
					tooltip: {
						visible: true,
						font: tooltipFont,
						template: barTooltipTemplate
					}
				})
			}
	
			$(function() {
				var pieCharts = "1,2,3,4,5,7,10,11,13,15,17,19";
				var barCharts = "6,9,12,14,16,18";
				var pieChartsArray = pieCharts.split(",");
				var barChartsArray = barCharts.split(",");
				if (pieChartsArray.length > 0) {
					for (var q = 0; q < pieChartsArray.length; q++) {
						renderPieChart(pieChartsArray[q]);
					}
				}
				if (barChartsArray.length > 0) {
					for (var q = 0; q < barChartsArray.length; q++) {
						renderBarChart(barChartsArray[q]);
					}
				}
			})
		
		</script>
		<style type="text/css">
			.k-chart {
				width: 800px;
				height: 400px;
			}
		</style>

		<cfoutput>
	
			<div class="accordion" id="esAccordian">
				<cfloop index="q" from="1" to="#ArrayLen(evaluations)#">
					<cfset totalExitSurveys = evaluations[q].Response_Count + evaluations[q].No_Response_Count />
					<cfset noResponsePercent = evaluations[q].No_Response_Count / totalExitSurveys * 100 />
					<cfset multiResponsePercent = evaluations[q].Multi_Response_Count / totalExitSurveys * 100 />
					<div class="accordion-group">
						<div class="accordion-heading"> <a class="accordion-toggle" data-toggle="collapse" data-parent="##esAccordian" href="##p#q#">#q#. #evaluations[q].Question#</a> </div>
						<div id="p#q#" class="accordion-body collapse<cfif q eq 1> in</cfif>">
							<div class="accordion-inner">
								<cfif q eq 8>
									Data can not be charted. 
								<cfelse>
									<ul class="nav nav-pills">
										<li class="active"><a href="##table#q#" data-toggle="pill">Table</a></li>
										<li><a href="##chart#q#" data-toggle="pill">Chart</a></li>
									</ul>
									<div class="tab-content">
										<div class="tab-pane active" id="table#q#">
											<table class="table table-hover table-bordered">
												<thead>
													<th>Answer</th>
													<th>Count</th>
													<th>Percent</th>
												
												<tbody>
													<cfloop index="a" from="1" to="#ArrayLen(evaluations[q].Answers)#">
														<tr>
															<td>#evaluations[q].Answers[a].Answer#</td>
															<td>#evaluations[q].Answers[a].Response_Count#</td>
															<td>#evaluations[q].Answers[a].Response_Percent#%</td>
														</tr>
													</cfloop>
													<tr>
														<td>Did not respond</td>
														<td>#evaluations[q].No_Response_Count#</td>
														<td>#DecimalFormat(noResponsePercent)#%</td>
													</tr>
													<cfif evaluations[q].Question_Type eq "Multiple select">
														<tr>
															<td>Multiple responses</td>
															<td>#evaluations[q].Multi_Response_Count#</td>
															<td>#DecimalFormat(multiResponsePercent)#%</td>
														</tr>
													</cfif>
												</tbody>
											</table>
										</div>
										<div class="tab-pane" id="chart#q#">
											<div id="q#q#Chart"></div>
										</div>
									</div>
								</cfif>
							</div>
						</div>
					</div>
				</cfloop>
			</div>
		
		</cfoutput>
		
	<cfelse>
	
		<div class="alert alert-info notFound">No exit surveys</div>

		<script type="text/javascript" language="javascript">
		<!--
			$(function() {
				$("#filter").show();
			});
		// -->
		</script>
		
	</cfif>

<cfelseif IsUserInRole("Organizer") or IsUserInRole("Site Contact")>

	<cfparam name="programYears" type="string" default="#request.currentProgramYear#" />
	<cfparam name="workshopIDs" type="string" default="All" />
	
	<cfscript>
		workshopGateway = new assets.calgrants.com.gateway.WorkshopGateway();
		workshops = workshopGateway.query(Program_Year = programYears, regionIDs = IIf(IsUserInRole("Regional Admin"), request.authUser.regionID, ""), Organization_ID = IIf(IsUserInRole("Organizer") OR IsUserInRole("Site Contact"), request.authUser.organizationID, ""), Manager_ID = IIf(IsUserInRole("Site Contact"), request.authUser.userID, ""));
		evaluationGateway = new assets.calgrants.com.gateway.EvaluationGateway();
		evaluations = evaluationGateway.report(
			organizationIDs = IIf(IsUserInRole("Organizer") OR IsUserInRole("Site Contact"), request.authUser.organizationID, ""), 
			workshopIDs = IIf(ListFind(workshopIDs, "All") eq 0 AND Len(Trim(workshopIDs)) gt 0, DE(workshopIDs), ""), 
			managerIDs = IIf(IsUserInRole("Site Contact"), request.authUser.userID, ""), 
			programYears = programYears
		);
	</cfscript>

	<cfif workshops.RecordCount gt 0>
	
		<cfset totalEvaluations = 0 />
		<cfset totalWorkshops = workshops.RecordCount/>
		<cfset validWorkshops = 0 />
		<cfset workshopsArray = ArrayNew(1) />
		<cfset selectedEvaluations = 0 />
		<cfset selectedWorkshops = 0 />
		<!--- <cfset selectedWorkshopIDs = "" /> --->
		<cfset selectedWorkshopsArray = ArrayNew(1) />
		<cfloop query="workshops">
			<cfset totalEvaluations = totalEvaluations + Student_Count />
			<cfif Student_Count gt 0>
				<cfset validWorkshops = IncrementValue(validWorkshops) />
			</cfif>
			<cfset workshopStruct = StructNew() />
			<cfset workshopStruct.workshopID = Workshop_ID />
			<cfset workshopStruct.workshop = "#Site#, #DateFormat(Workshop_Date, 'm/d/yyyy')# #TimeFormat(Start_Time, 'h:mmtt')#-#TimeFormat(End_Time, 'h:mmtt')#" />
			<cfset workshopStruct.studentCount = Student_Count />
			<cfif (ListFind(workshopIDs, "All") gt 0 OR ListFind(workshopIDs, Workshop_ID) gt 0) AND Student_Count gt 0>
				<cfset selectedEvaluations = selectedEvaluations + Student_Count />
				<cfset selectedWorkshops = IncrementValue(selectedWorkshops) />
				<!--- <cfset selectedWorkshopIDs = ListAppend(selectedWorkshopIDs, Workshop_ID) /> --->
				<cfset workshopStruct.selected = true />
			<cfelse>
				<cfset workshopStruct.selected = false />
			</cfif>
			<cfset ArrayAppend(workshopsArray, workshopStruct) />
		</cfloop>
		
		<cfform id="selectWorkshopsForm" action="#script_name#" method="post">
			<cfinput type="hidden" name="view" value="#view#" />
			
			<cfoutput>
			<p><button type="button" id="filterButton" name="filterButton" onclick="filter(); return false;" class="btn btn-success">Filter</button>&nbsp;<a id="exportButton" href="?action=export&collection=evaluations&workshopIDs=#workshopIDs#" target="_new" class="btn btn-success">Export</a>&nbsp;<!--- <a href="/documents/2013-2014_Cash_for_College_Exit_Survey_Key.pdf" target="_blank">Exit Survey Key</a>&nbsp; ---><button type="button" id="cancelFilterButton" name="cancelFilterButton" onclick="cancelFilter(); return false;" class="btn btn-success" style="display: none;">Cancel</button>&nbsp;<button type="submit" id="applyFilterButton" name="applyFilterButton" class="btn btn-success" style="display: none;">Apply</button>
	
				<table id="workshopsTable" class="table table-hover table-bordered">
					<thead>
						<tr>
							<th class="checkboxCol"></th>
							<th>Workshop</th>
							<th>Exit Surveys</th>
						</tr>
					</thead>
					<tbody>
						<cfloop index="w" from="1" to="#ArrayLen(workshopsArray)#">
							<tr class="#IIf(workshopsArray[w].selected, DE('selected'), DE('unselected'))#">
								<td class="checkboxCol">
									<cfif workshopsArray[w].studentCount gt 0>
										<input type="checkbox" name="workshopIDs" value="#workshopsArray[w].workshopID#"<cfif ListFind(workshopIDs, "All") gt 0 OR ListFind(workshopIDs, workshopsArray[w].workshopID) gt 0> class="selectedWorkshop" checked</cfif>>
									</cfif>
								</td>
								<td>#workshopsArray[w].workshop#</td>
								<td style="width: 100px;">#workshopsArray[w].studentCount#</td>
							</tr>
						</cfloop>
					</tbody>
				</table>
				
			</cfoutput>
			
		</cfform>
	
		<script type="text/javascript">
			
			var filter = function() {
				$("#filterButton").hide();
				$("#cancelFilterButton").show();
				$("#applyFilterButton").show();
				$(".unselected").show();
				$(".checkboxCol").show();
				$("#exportButton").hide();
			}
			
			var cancelFilter = function() {
				$("#cancelFilterButton").hide();
				$("#filterButton").show();
				$("#applyFilterButton").hide();
				$(".unselected").hide();
				$(".checkboxCol").hide();
				$("#exportButton").show();
				$.each($(".selectedWorkshop"), function(i,e) {
					e.checked = true;
				});
				//var workshopCheckboxes = $(".workshopCheckboxes");
				//for (var i = 0; i < selectedWorkshopIDs.length; i++) {
					//if (selectedWorkshopIDs[i].val()	
				//}
			}
			
			var toggleOthers = function(e) {
				if (e.checked) {
					$(".otherCheckbox").prop("checked", false);
				}
			}
			
			var toggleAll = function(e) {
				if (e.checked) {
					$(".allCheckbox").prop("checked", false);
				}
			}							
			
			$(function() {
				$(".unselected").hide();
				$(".checkboxCol").hide();
			})
		</script>
		
		<cfif ArrayLen(evaluations) gt 0>
		
			<script type="text/javascript">
				
				var parseQuestions = function(questions) {
					for (var q = 0; q < questions.length; q++) {
						questions[q].QUESTION_NUMBER = parseInt(questions[q].QUESTION_NUMBER);
						questions[q].RESPONSE_COUNT = parseInt(questions[q].RESPONSE_COUNT);
						questions[q].MULTI_RESPONSE_COUNT = parseInt(questions[q].MULTI_RESPONSE_COUNT);
						questions[q].NO_RESPONSE_COUNT = parseInt(questions[q].NO_RESPONSE_COUNT);
					}
					return questions;
				}
				
				var parseAnswers = function(answers) {
					for (var a = 0; a < answers.length; a++) {
						if (answers[a].ANSWER === true) {
							answers[a].ANSWER = "Yes ";
						} else if (answers[a].ANSWER === false) {
							answers[a].ANSWER = "No ";
						}
						answers[a].ANSWER_NUMBER = parseInt(answers[a].ANSWER_NUMBER);
						answers[a].RESPONSE_COUNT = parseInt(answers[a].RESPONSE_COUNT);
						answers[a].RESPONSE_PERCENT = parseFloat(answers[a].RESPONSE_PERCENT);
						//answers[a].RESPONSE_OTHER = answers[a].ANSWER_VALUES.toString();
						answers[a].EXPLODE = false;
					}
					return answers;
				}
		
				<cfoutput>
					var questions = #SerializeJSON(evaluations)#;
				</cfoutput>
				
				var pieLabelTemplate = "#= dataItem.ANSWER# - #= dataItem.RESPONSE_PERCENT#%";
				var pieLegendTemplate = "#= dataItem.ANSWER# - #= dataItem.RESPONSE_PERCENT#%";
				//var pieTooltipTemplate = "#= dataItem.ANSWER# - #= dataItem.RESPONSE_COUNT#";
				var pieTooltipTemplate = "#= dataItem.RESPONSE_COUNT# responses = #= dataItem.RESPONSE_PERCENT#%";
				var barLabelTemplate = "#= dataItem.ANSWER# - #= dataItem.RESPONSE_PERCENT#%";
				var barLegendTemplate = "#= text#";
				var barTooltipTemplate = "#= dataItem.RESPONSE_COUNT# responses = #= dataItem.RESPONSE_PERCENT#%";
				var labelFont = "12px Arial,Helvetical,sans-serif";
				var legendFont = "12px Arial,Helvetical,sans-serif";
				var tooltipFont = "12px Arial,Helvetical,sans-serif";
				
				renderPieChart = function(q) {
					var question = questions[q-1];
					var answers = parseAnswers(question.ANSWERS);
					$("#q" + q + "Chart").kendoChart({
						theme: $(document).data("kendoSkin") || "metro",
						dataSource: answers,
						series: [{
							type: "pie",
							field: "RESPONSE_PERCENT",
							categoryField: "ANSWER",
							explodeField: "EXPLODE",
							labels: {
								visible: true,
								align: "circle",
								font: labelFont,
								template: pieLabelTemplate,
								distance: 20
							},
							//padding: 0
						}],
						legend: {
							visible: false,
							position: "left",
							labels: {
								font: legendFont,
								template: pieLegendTemplate
							}
						},
						tooltip: {
							visible: true,
							font: tooltipFont,
							template: pieTooltipTemplate
						}
					})
				}
				
				renderBarChart = function(q) {
					var question = questions[q-1];
					var answers = parseAnswers(question.ANSWERS);
					$("#q" + q + "Chart").kendoChart({
						theme: $(document).data("kendoSkin") || "metro",
						dataSource: answers,
						series: [{
							type: "bar",
							field: "RESPONSE_PERCENT",
							categoryField: "ANSWER",
							labels: {visible: true, font: labelFont, template: barLabelTemplate, position: "outsideEnd"},
							missingValue: "zero",
							gap: 0.4,
							spacing: 0.2,
							markers: {visible: true, border: {width: 2, size: 6}},
							//padding: 0
						}],
						valueAxis: {
							title: {visible: false, text: "valueAxis"},
							labels: {template: "#= value#%"},
							majorGridLines: {visible: true, color: "gray"},
							majorTicks: {visible: true, color: "gray"},
							minorGridLines: {visible: true, color: "silver"},
							minorTicks: {visible: true, color: "silver"},
							plotBands: [{
								from: 49,
								to: 51,
								color: "gray",
								opacity: 0.3
							}]
						},
						categoryAxis: {
							title: {visible: false, text: "categoryAxis"},
							majorGridLines: {visible: false},
							majorTicks: {visible: false}
						},
						legend: {
							visible: false,
							position: "left",
							labels: {font: legendFont, template: barLegendTemplate}
						},
						tooltip: {
							visible: true,
							font: tooltipFont,
							template: barTooltipTemplate
						}
					})
				}
		
				$(function() {
					var pieCharts = "1,2,3,4,5,7,10,11,13,15,17,19";
					var barCharts = "6,9,12,14,16,18";
					var pieChartsArray = pieCharts.split(",");
					var barChartsArray = barCharts.split(",");
					if (pieChartsArray.length > 0) {
						for (var q = 0; q < pieChartsArray.length; q++) {
							renderPieChart(pieChartsArray[q]);
						}
					}
					if (barChartsArray.length > 0) {
						for (var q = 0; q < barChartsArray.length; q++) {
							renderBarChart(barChartsArray[q]);
						}
					}
				})
			
			</script>
			<style type="text/css">
				.k-chart {
					width: 600px;
					height: 400px;
				}
			</style>
			<div class="accordion" id="esAccordian">
				<cfoutput>
					<cfloop index="q" from="1" to="#ArrayLen(evaluations)#">
						<div class="accordion-group">
							<div class="accordion-heading"> <a class="accordion-toggle" data-toggle="collapse" data-parent="##esAccordian" href="##p#q#">#q#. #evaluations[q].Question#</a> </div>
							<div id="p#q#" class="accordion-body collapse<cfif q eq 1> in</cfif>">
								<div class="accordion-inner">
									<table class="table table-hover table-bordered">
										<tr>
											<th>Responses</th>
											<td>#evaluations[q].Response_Count#</td>
										</tr>
										<tr>
											<th>Non-responses</th>
											<td>#evaluations[q].No_Response_Count#</td>
										</tr>
										<cfif evaluations[q].Question_Type eq "Multiple select">
											<tr>
												<th>Multi-responses</th>
												<td>#evaluations[q].Multi_Response_Count#</td>
											</tr>
										</cfif>
									</table>
									<cfif q eq 8>
										Data can not be charted. 
									<cfelse>
										<ul class="nav nav-pills">
											<li class="active"><a href="##table#q#" data-toggle="pill">Table</a></li>
											<li><a href="##chart#q#" data-toggle="pill">Chart</a></li>
										</ul>
										<div class="tab-content">
											<div class="tab-pane active" id="table#q#">
												<table class="table table-hover table-bordered">
													<thead>
														<th>Answer</th>
														<th>Count</th>
														<th>Percent</th>
													
													<tbody>
														<cfloop index="a" from="1" to="#ArrayLen(evaluations[q].Answers)#">
															<tr>
																<td>#evaluations[q].Answers[a].Answer#</td>
																<td>#evaluations[q].Answers[a].Response_Count#</td>
																<td>#evaluations[q].Answers[a].Response_Percent#%</td>
															</tr>
														</cfloop>
													</tbody>
												</table>
											</div>
											<div class="tab-pane" id="chart#q#">
												<div id="q#q#Chart"></div>
											</div>
										</div>
									</cfif>
								</div>
							</div>
						</div>
					</cfloop>
				</cfoutput>
			</div>
			
		<cfelse>
		
			<p>No exit surveys found</p>
			
		</cfif>
		
	<cfelseif workshops.RecordCount eq 0>
	
		<p>No workshops found</p>
		
	</cfif>
	
</cfif>